package com.lagou.firststage.fourmode;

/**
 * @author：dingyuan
 * @date：Created in 2022/1/15 21:48
 * @description：员工类
 * @version: 1.0
 */
public class Staff {
    private String name;
    private int age;

    public Staff(String name, int age) throws AgeException {
        setName(name);
        setAge(age);
    }

    public Staff() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name != null){
            this.name = name;
        }else {
            throw new NullPointerException();
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if( 18 <= age && age <= 150){
            this.age = age;
        }else {
            throw new AgeException("The param {} age is illegal");
        }
    }

    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
